/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.

// InstallerSpec defines the desired state of Installer
type InstallerSpec struct {
	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
	// Important: Run "make" to regenerate code after modifying this file

	SvcYamlPath    string                       `json:"svc_yaml_path,omitempty"`
	Middlewares    map[string]MiddleInfo        `json:"middlewares,omitempty"`
	NamespaceName  string                       `json:"namespaceName,omitempty"`
	LecangApps     map[string]appInfo           `json:"lecangApps"`
	LecangAppsVue  map[string]appInfo           `json:"lecangAppsVue"`
	InitImage      string                       `json:"initImage"`
	Configmaps     map[string]map[string]string `json:"configmaps"`
	NfsProvisioner NfsProvisionerInfo           `json:"nfsProvisioner,omitempty"`
	Storage        StorageInfo                  `json:"storage"`
}

type MiddleInfo struct {
	Name            string `json:"name"`
	Image           string `json:"image"`
	Port            int    `json:"port"`
	NodePort        int    `json:"nodePort"`
	HttpPort        int    `json:"httpPort,omitempty"`
	HttpNodePort    int    `json:"httpNodePort,omitempty"`
	EnableHttpPort  bool   `json:"enableHttpPort,omitempty"`
	EnableService   bool   `json:"enableService,omitempty"`
	EnableConfigmap bool   `json:"enableConfigmap"`
	LimitLevel      int    `json:"limitLevel"`
}

type appInfo struct {
	Image           string `json:"image"`
	EnableNodePort  bool   `json:"enableNodePort"`
	NodePort        int32  `json:"nodePort"`
	EnableService   bool   `json:"enableService,omitempty"`
	EnableConfigmap bool   `json:"enableConfigmap,omitempty"`
	LimitLevel      int    `json:"limitLevel"`
}

type NfsProvisionerInfo struct {
	Name                string   `json:"name"`
	Enable              bool     `json:"enable"`
	NfsServer           string   `json:"nfsServer"`
	NfsPath             string   `json:"nfsPath"`
	StorageClassNames   []string `json:"storageClassNames"`
	StorageSize         string   `json:"storageSize"`
	PvcNames            []string `json:"pvcNames"`
	PvcStorageClassName string   `json:"pvcStorageClassName"`
}

type StorageInfo struct {
	PvcNames            []string `json:"pvcNames"`
	PvNames             []string `json:"pvNames"`
	StorageSize         string   `json:"storageSize"`
	PvLocalPath         string   `json:"pvLocalPath"`
	PvNodeName          string   `json:"pvNodeName"`
	PvcStorageClassName string   `json:"pvcStorageClassName"`
	PvStorageClassName  string   `json:"pvStorageClassName"`
}

// InstallerStatus defines the observed state of Installer
type InstallerStatus struct {
	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
	// Important: Run "make" to regenerate code after modifying this file
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Installer is the Schema for the installers API
type Installer struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   InstallerSpec   `json:"spec,omitempty"`
	Status InstallerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// InstallerList contains a list of Installer
type InstallerList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Installer `json:"items"`
}

func init() {
	SchemeBuilder.Register(&Installer{}, &InstallerList{})
}
